Got a function to create a 'field' but putting the label on top instead of to the side.
DB VerticalField_dbPrevious = null
DBE VerticalField_dbePrevious = null
//*****************************************************
DBE fdbe_VerticalField(bool in_Adjacent, DB in_db, string in_Label, in_Initial, int in_Width, bool in_ReadOnly)
{ // Build a 'field' DBE such that the label is above the field rather than to the left.
// Return the created 'field's DBE (e.g. for future 'get' and 'set' commands)
// When in_Adjacent then ignore the current Simple Placement position
// and instead put the new VerticalField next to the previous VerticalField on this dialog.
// When not in_Adjacent then respect the current Simple Placement position.
// The other input Parameters are the same as for the native 'field' command.
// VerticalFields are useful to line up rows and columns of fields nicely
// without concern for the various lengths of Labels on those fields.
// This technique requires two additional DBEs unknown to the calling program,
// The first is an Invisible field exactly same size as desired
// The second is a visible label directly on top of the invisible field
// The real field is positioned below the invisible field.
// This function is intended for Simple Placement. Programs that wish Contrained Placement can awkwardly do this:
// To Contrained the Placement OF this field:
// This is not supported as no method for doing so was found,
// although the caller using an invisible 'frame' worked some, but the label had
// to go inside and it didn't line up quite right.
// To Constrain the Placement of other DBEs based ON this field:
// Get a handle of the invisible field above the live field by doing this right after the call:
// DBE dbeFieldLabel = VerticalField_dbePrevious
// Perform future horizontal placement based on that
DBE dbeField, dbeInvisible, dbeLabel
// We cannot actually do 'Adjacent' to previous VerticalField unless this DB
// already has such a VerticalField
bool DoAdjacent = in_Adjacent and
(!null VerticalField_dbePrevious) and
(in_db == VerticalField_dbPrevious)
// [1] Create Invisible DBE field at right spot, same size as desired field
dbeInvisible = field(in_db, "", "", in_Width, true)
hide(dbeInvisible) // Hide the temp field
if (DoAdjacent)
{ dbeInvisible ->"left" ->"flush" ->VerticalField_dbePrevious
dbeInvisible ->"top" ->"aligned" ->VerticalField_dbePrevious
}
else
{ //dbeInvisible ->"left" ->"form"
}
stacked(dbeInvisible) // dbeLabel goes on top
// [2] Create the visible Label, positioned right on top of the Invisible field
dbeLabel = label(in_db, in_Label)
dbeLabel ->"top" ->"aligned" ->dbeInvisible // ?? This makes additional labels in the right horizontal spot
if (DoAdjacent) //
then dbeLabel ->"left" ->"spaced" ->VerticalField_dbePrevious // Up against previous invis field
else{} // leave label up against whatever is there
// [3] Finally create the desired field, positioned right below the invisible one
dbeField = field(in_db, "", in_Initial, in_Width, in_ReadOnly)
dbeField ->"left" ->"aligned" ->dbeInvisible
dbeField ->"top" ->"flush" ->dbeLabel
// [4] Remember 'Previous' for future 'Adjacent' requests, if any
VerticalField_dbePrevious = dbeInvisible
VerticalField_dbPrevious = in_db
return(dbeField)
} // end fdbe_VerticalField()
DB db
DBE dbe1, dbe2, dbe3, dbe4, dbe5, dbe6
void applyRead(DB dbXX)
{ infoBox((string get(dbe1)) "\n" (string get(dbe2)) "\n" (string get(dbe3)) "\n" (string get(dbe4)))
}
void btnTemp(DBE dbeXX)
{ // some callback for this dialog
}
db = create("ddd")
dbe1 = fdbe_VerticalField(true, db, "Field1", "Field1Init", 20, true) // Adjacent is ignored for this first DBE
dbe2 = fdbe_VerticalField(true, db, "Field2", "Field2 Init", 30, false)
dbe3 = fdbe_VerticalField(true, db, "Field3", "ddd", 40, false)
left(db)
dbe4 = fdbe_VerticalField(false, db, "Field4", "ddd", 40, false)
beside(db)
dbe5 = toggle(db, "Toggle5", true)
dbe5 ->"top" ->"spaced" ->dbe2
// Change to 'true' and it covers Toggle5:
dbe6 = fdbe_VerticalField(false, db, "Field6", "ddd", 10, false)
apply(db, "Read", applyRead)
realize(db, 100, 700)
show(db)
llandale - Thu Aug 25 17:06:04 EDT 2011 |
Re: fdbe_VerticalField I know you do not like all that struct stuff and might not see the point, but I think the example attached shows
The code does at the moment not support "bottom" and "right" glues, as long as you keep the placement "top" and "left" it should be fine. Hope the comments explain the most important parts, if you find bugs we can try to solve them. Hope that helps, Regards, Mathias Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS Attachments attachment_14676544_VerticalField.dxl |
Re: fdbe_VerticalField Mathias Mamsch - Fri Aug 26 08:47:06 EDT 2011
The code does at the moment not support "bottom" and "right" glues, as long as you keep the placement "top" and "left" it should be fine. Hope the comments explain the most important parts, if you find bugs we can try to solve them. Hope that helps, Regards, Mathias Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS Regards, Mathias Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS |
Re: fdbe_VerticalField Mathias Mamsch - Fri Aug 26 08:51:18 EDT 2011 Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
You may very well drag me into the 1990s, but I sure you realize it will be kicking and screaming.
// ************** Test Dialog ************************
DB db = centered "Test"
VerticalField dbe1 = createVerticalField(db, "Field1", "Field1Init", 20, true) // Adjacent is ignored for this first DBE
dbe1 -> "top" -> "form"
dbe1 -> "left" -> "form"
VerticalField dbe2 = createVerticalField(db, "Field2", "Field2 Init", 30, false)
dbe2 -> "top" -> "form"
dbe2 -> "left" -> "spaced" -> dbe1
DBE dbeT = toggle(db, "Toggle", true)
VerticalField dbe3 = createVerticalField(db, "Field3", "ddd", 40, false)
dbe3 -> "top"->"aligned" -> dbeT
dbe3 -> "left" -> "spaced" -> dbeT
// beside db
VerticalField dbe4 = createVerticalField(db, "Field4", "xxx", 30, false)
DBE dbeF = field(db, "normalField", "aa", 20, true)
VerticalField dbe5 = createVerticalField(db, "Field5", "xxx", 30, false)
beside(db)
DBE dbeT2 = toggle(db, "Toggle2", false)
dbeT2 ->"left" ->"spaced" ->dbe5
left(db)
void myButtonCallback (DBE x) { ack "GLUED!" }
DBE myButton = button (db, "Glue me to teh field!", myButtonCallback)
myButton -> "top" -> "spaced" -> dbe3
myButton -> "left" -> "spaced" -> dbe1
DBE dbeLab = label(db, "")
dbeLab ->"top" ->"spaced" ->dbe5
// realize(db, 100, 700)
show(db)
|